#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "pkgFlow.h"

static u32 randIP(void)
{
    u32 ret = 0;

    for (int i = 0; i < 4; i++)
    {
        srand(rand());
        ret <<= 8;
        ret += ((rand() % 256) & 0x000000FF);
    }

    return ret;
}

// 随机生成数据包数量
int getAmount(void)
{
    srand(time(NULL));
    // srand(rand());

    return rand() % MAX_AMOUNT + 1;
}

// 获得数据包
Package * getFlow(int amount, Package * IPsets)
{
    // for (int i = 0; i < amount; i++)
    // {
    //     srand(rand());
    //     (IPsets + i)->srcIP = randIP();
    //     // printf("(IPsets + i)->srcIP = %8x\n", (IPsets + i)->srcIP);
    //     (IPsets + i)->dstIP = randIP();
    //     (IPsets + i)->timestamp = time(NULL) + rand() % 3600;
    // }

    // test
    IPsets->srcIP = 0x490a06bc;
    IPsets->dstIP = 0x7157089d;
    IPsets->timestamp = time(NULL) - TTL;
    IPsets->srcPort = 0xcc;
    IPsets->dstPort = 0xaf;
    IPsets->protocol = 1;
    IPsets->netcard = 1;
    for (int i = 1; i < amount; i++)
    {
        srand(rand());
        (IPsets + i)->srcIP = randIP();
        // printf("(IPsets + i)->srcIP = %8x\n", (IPsets + i)->srcIP);
        (IPsets + i)->dstIP = randIP();
        (IPsets + i)->timestamp = time(NULL) - rand() % 3600;
        (IPsets + i)->srcPort = rand() % 0xffff + 1;
        (IPsets + i)->dstPort = rand() % 0xffff + 1;
        (IPsets + i)->protocol = rand() % (NUM_PROTOCOL - 1) + 1;
        (IPsets + i)->netcard = rand() % (NUM_NETCARD - 1) + 1;
    }

    return IPsets;
}